{snippet comment}
  {if $presenter->user->isLoggedIn()}
    {form commentForm class=>ajax-form}
      <ul class="errors" n:if="$form->hasErrors()">
          <li n:foreach="$form->errors as $error">{$error}</li>
      </ul>
      
      <div class="form form-row">
        {input text class=>array(form, form-text-area)}
      </div>
      
      <div class="button-row center">
        {input send class=>array(button, standard)}
      </div>
    {/form}
  {else}
    Abyste mohli psát své názory, musíte se přihlásit
  {/if}
  <div class="comment-list">
    {foreach $comments as $comment}
      <div class="comment-detail">
        {var $date = date("d.m.Y H:i", strtotime($comment->comment_published))}
        <p><strong>{$comment->user->login}</strong><span class="comment-date"> - {$date}</span></p>
        <p>{$comment->text}</p>
      </div>
    {/foreach}
  </div>
  
  <div class="comments-pagination">
    {if $offset != 0}
      <a class="ajax left" n:href="page! offset=>$offset-$limit"></a>
    {else}
      <a class="ajax left pasive" href="#"></a>
    {/if}
    
    <span>{$currentPage + 1} / {$pagesTotal + 1}</span>
    
    {if ($offset + $limit) < $commentsCount}
      <a class="ajax right" n:href="page! offset=>$offset+$limit"></a>
    {else}
      <a class="ajax right pasive" href="#"></a>
    {/if}
  </div>
  
  <script>
   $(document).ready(function(){
    jQuery.ajaxSetup({
     cache: false,
     dataType: 'json',
     success: function (payload) {
      console.log(payload);
       if (payload.snippets) {
         for (var i in payload.snippets) {
           $('#' + i).html(payload.snippets[i]);
         }
       }
     },
             
     fail: function(error){
      console.log(error);
     }
   });

   $('.ajax').click(function (event) {
     event.preventDefault();
     $.post($(this).attr('href'), $(this).serialize());
   });
   
    $('.ajax-form').submit(function (event) {
      event.preventDefault();
      $.post($(this).attr('action'), $(this).serialize());
    });
  });
  
  </script>
  
{/snippet}

